package com.yugong.controller;

import com.yugong.common.Result;
import com.yugong.entity.vo.request.AccountRequestVO;
import com.yugong.entity.vo.response.AccountListResponseVO;
import com.yugong.service.AccountService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 账户控制器类
 *
 * @author yugong
 * @date 2024/2/9
 */
@Validated
@RestController
@RequestMapping("/api/account")
public class AccountController {
    @Resource
    private AccountService accountService;

    /**
     * 用户登录
     *
     * @param accountRequestVO 登录信息
     * @return 用户信息
     */
    @PostMapping("/account-login")
    public Result accountLogin(@RequestBody AccountRequestVO accountRequestVO) {
        AccountListResponseVO accountListResponseVO = accountService.accountLogin(accountRequestVO);
        return Result.success(accountListResponseVO);
    }

    /**
     * 用户注册
     *
     * @param accountRequestVO 注册信息
     * @return 响应码
     */
    @PostMapping("/account-register")
    public Result accountRegister(@RequestBody AccountRequestVO accountRequestVO) {
        int registerFlag = accountService.accountRegister(accountRequestVO);
        return Result.success(registerFlag);
    }

    /**
     * 查询账号列表
     *
     * @return 账号列表
     */
    @GetMapping("/account-no-list")
    public Result accountNoList() {
        List<String> accountNoList = accountService.accountNoList();
        return Result.success(accountNoList);
    }

    /**
     * 用户重置
     *
     * @param accountRequestVO 用户请求实体类
     * @return 响应码
     */
    @PutMapping("/account-reset")
    public Result accountReset(@RequestBody AccountRequestVO accountRequestVO) {
        int updateFlag = accountService.accountReset(accountRequestVO);
        return Result.success(updateFlag);
    }
}
